package com.huge.simple.common.request;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author jihu
 * date 2022-03-29
 */
@ApiModel("分页查询请求对象")
public class RequestParameter<T> {

    @ApiModelProperty("页码")
    private Long pageNum = 1L;

    @ApiModelProperty("页长")
    private Long pageSize = 15L;

    @ApiModelProperty("排序")
    private OrderItem[] orderItems;

    @ApiModelProperty("查询对象")
    private T filter;

    public Page<T> getPage(){
        Page<T> page = new Page<>();
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        if(orderItems != null && orderItems.length >= 1){
            page.addOrder(orderItems);
        }
        return page;
    }

    public Long getPageNum() {
        return pageNum;
    }

    public RequestParameter<T> setPageNum(Long pageNum) {
        this.pageNum = pageNum;
        return this;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public RequestParameter<T> setPageSize(Long pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    public OrderItem[] getOrderItems() {
        return orderItems;
    }

    public RequestParameter<T> setOrderItems(OrderItem[] orderItems) {
        this.orderItems = orderItems;
        return this;
    }

    public T getFilter() {
        return filter;
    }

    public RequestParameter<T> setFilter(T filter) {
        this.filter = filter;
        return this;
    }
}
